package com.suppet.radis;

import com.suppet.pojo.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Set;

@SpringBootTest
public class RedisTest {
    @Autowired
   private RedisTemplate redisTemplate;
    @Test
    public void test01(){
        ValueOperations ops = redisTemplate.opsForValue();
        ops.set("city","广州");
        Object city = ops.get("city");
        System.out.println(city);
    }
   // @Test
//    public void test02(){
//        ListOperations list = redisTemplate.opsForList();
//        Book book1=new Book(1, "西游记", 28.56d, "人民出版社", LocalDate.now(), "吴承恩");
//        Book book2 = new Book(2, "红楼梦", 35.20d, "人民文学出版社", LocalDate.now(), "曹雪芹");
//        Book book3 = new Book(3, "三国演义", 30.80d, "上海古籍出版社", LocalDate.now(), "罗贯中");
//        list.leftPushAll("book:list",)
//    }

    @Test
    public void test03(){
        HashOperations hash = redisTemplate.opsForHash();
        hash.put("car:100","name","奥迪");
        hash.put("car:100", "price", 300000d);
        hash.put("car:100", "color", "黑色");
        Object name = hash.get("car:100", "name");
        System.out.println("车名"+name);
        Map entries = hash.entries("car:100");
        System.out.println("所有字段和值："+entries);
        Set keys = hash.keys("car:100");
        System.out.println("键"+keys);
        List values = hash.values("car:100");
        System.out.println(values);
    }
    @Test
    public void test04(){
        SetOperations set = redisTemplate.opsForSet();
       set.add("car", 1,2,3,4,5,6);
       set.add("car1", 1,2,4,7,8);
       set.add("car2",  3,5,7,1);
        Set difference = set.difference("car1", "car2");
        System.out.println("差值"+difference);
        Set union = set.union("car1", "car2");
        System.out.println("并集："+union);
        Set intersect = set.intersect("car", "car1");
        System.out.println("交集："+intersect);

    }
}
